package com.yanze.controller;

import com.yanze.pojo.Issue;
import com.yanze.pojo.request.ReqIssue;
import com.yanze.service.IssueService;
import com.yanze.utils.BaseJSONResult;
import com.yanze.utils.C;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("issue")
public class IssueController {

    @Autowired
    IssueService mIssueService;

    @RequestMapping(path = "/addissue",method = RequestMethod.POST)
    public BaseJSONResult insertIssue(@RequestBody ReqIssue issue) {
        if (issue == null) {
            return BaseJSONResult.errorMsg("参数错误");
        }
        Issue s = new Issue();
        s.setIssue(issue.getContent());
        s.setContact(issue.getContact());
        s.setTime(new Date());
        int flag = mIssueService.addIssue(s);
        if (flag > 0) {
            return BaseJSONResult.ok();
        }else{
            return BaseJSONResult.errorMsg(C.errmsg.insertError);
        }
    }

}
